package com.sss.otep.ws.endpoints;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;

import com.sss.otep.message.schemas.MemberRequest;
import com.sss.otep.message.schemas.MemberResponse;
import com.sss.otep.orm.model.Member;
import com.sss.otep.service.LoadParameter;
import com.sss.otep.service.OTEPService;
import com.sss.otep.util.SchemaConvertionUtils;

@Endpoint
public class CPKMemberEndPoint implements CPKEndpoint{
	private static final Logger log = LoggerFactory.getLogger(CPKMemberEndPoint.class);
	
		
	@Autowired
	private OTEPService service;
	
	@PayloadRoot(localPart="MemberRequest", namespace = NAMESPACE)
	public MemberResponse getMember(MemberRequest param){
		log.info("invoke member endpoint");				
		MemberResponse response = new MemberResponse();
		try{
			LoadParameter loadParam = new LoadParameter();
			
			
			loadParam.setId(param.getId());		
			loadParam.setIdCard(param.getIdCard());
			loadParam.setName(param.getName());
			loadParam.setSurname(param.getSurname());
			List<Member> result = service.loadMember(loadParam);
			for(Member m : result){
				response.getMember().add(SchemaConvertionUtils.toSchema(m));
			}
			
			
		}catch(Exception e){
			log.error("Member-end-point error occured !!",e);
		}
		return response;
	}
}
